package com.schoolcloud.front.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.schoolcloud.common.model.PageDTO;
import com.schoolcloud.front.entity.FroSchool;
import com.schoolcloud.front.query.FroSchoolQuery;
import com.schoolcloud.front.service.FroSchoolService;
import com.schoolcloud.front.mapper.FroSchoolMapper;
import com.schoolcolud.daomybatisplus.dto.MpPageUtil;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author hongmizfb
 * @description 针对表【fro_school(校园表)】的数据库操作Service实现
 * @createDate 2025-02-16 14:06:13
 */
@Service
public class FroSchoolServiceImpl extends ServiceImpl<FroSchoolMapper, FroSchool>
        implements FroSchoolService {

    @Override
    public PageDTO<FroSchool> getFroSchoolPage(FroSchoolQuery query) {
        String keywords = query.getKeywords();
        Page<FroSchool> page = lambdaQuery().eq(StrUtil.isNotBlank(keywords), FroSchool::getSchoolName, keywords)
                .page(query.toMpPage());
        return MpPageUtil.of(page, FroSchool.class);
    }

    @Override
    public FroSchool createFroSchool(FroSchool froSchool) {
        froSchool.setCreateTime(new Date());
        save(froSchool);
        return froSchool;
    }

    @Override
    public FroSchool updateFroSchool(FroSchool froSchool) {
        updateById(froSchool);
        return froSchool;
    }
}




